{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7b920fb8",
   "metadata": {},
   "source": [
    "## 字典的查询\n",
    "* 1.in方法查询\n",
    "* 2.get方法获取"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49e6cc28",
   "metadata": {},
   "source": [
    "## 字典的删除\n",
    "1.pop()指定值删除\n",
    "2.popitem()随机删除"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88bd08b9",
   "metadata": {},
   "source": [
    "## 字典的一般方法\n",
    "* 1.字典的循环遍历\n",
    "* 2.fromkeys()方法\n",
    "* 3.setdefault()方法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b9d3041e",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu10001\":\"xiaoming\",\n",
    "    \"stu10002\":\"lihua\",\n",
    "    \"stu10003\":\"xiaohong\",\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae00e620",
   "metadata": {},
   "source": [
    "### 1.字典循环遍历\n",
    "* 字典的循环遍历循环的是两个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "134d42cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10001 xiaoming\n",
      "10002 lihua\n",
      "10003 xiaohong\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历字典\n",
    "# 循环遍历最大的用途就是：给所有的值使用同样的操作\n",
    "stu_id_list = []\n",
    "for k,v in info.items():\n",
    "    print(k[3:],v)\n",
    "    stu_id_list.append(k[3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ec0dbcca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['10001', '10002', '10003']\n"
     ]
    }
   ],
   "source": [
    "print(stu_id_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80a9687c",
   "metadata": {},
   "source": [
    "* 练习：info的value目前的格式进行统一修改，修改的范式为：姓 名 xiao ma"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2540fd6",
   "metadata": {},
   "source": [
    "### 2.fromkeys()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1189c0ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1': 123456, 'stu2': 123456}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 初始化统一值的字典信息\n",
    "初始密码 = {}\n",
    "初始密码.fromkeys([\"stu1\",\"stu2\"],123456)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69614f6c",
   "metadata": {},
   "source": [
    "### 3.setdefault()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ab3e8ff9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'xiaoma'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info.setdefault('stu10004','xiaoma')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "855a4ad5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu10001': 'xiaoming', 'stu10002': 'lihua', 'stu10003': 'xiaohong', 'stu10004': 'xiaoma'}\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2361b866",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
